package com.project.controller;

import com.project.bean.ColumnBean;
import com.project.service.IColumnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("column")
public class ColumnController {
    @Autowired
    private IColumnService service;

    @RequestMapping("findColumnCount")
    public String[][] findColumnCount(Integer year) {
        List<ColumnBean> columnBeanList = service.findColumnCount(year);

        String [][] strings = new String[13][5];
        strings[0] = new String []{"类别", "电脑产品", "安防产品", "打印扫描设备","办公耗材"};
        Map<String,Integer> map = new HashMap<>(){{put("家电",1);put("汽车零配件",2);put("电脑与电子用品",3);put("测试3R",4);}};
        for (int i = 1; i < 13; i++) {
            for (int j = 0; j < 5; j++) {
                if(j==0){
                    strings[i][j] = i+"月";
                    continue;
                }
                strings[i][j] = "0";
            }
        }
        for (ColumnBean c: columnBeanList) {
            if ("家电".equals(c.getType())||"汽车零配件".equals(c.getType())||"电脑与电子用品".equals(c.getType())||"测试3R".equals(c.getType()))
            strings[Integer.parseInt(c.getMonth())] [map.get(c.getType())]= c.getNum();
        }

        for (int i = 0; i < 13; i++) {
            for (int j = 0; j < 5; j++) {
                System.out.print( strings[i][j]+"\t");
            }
            System.out.println();
        }
        return strings;
    }
}
